//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	IEntityList.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using System.Collections.Generic;

namespace Smart.Common.Entities
{
	/// <summary>
	/// Entity List collection
	/// </summary>
	public interface IEntityList
	{
		/// <summary>
		/// Fields service
		/// </summary>
		MetaFields Meta { get; }

		/// <summary>
		/// Load entity
		/// </summary>
		bool Load(Entity entity);

		/// <summary>
		/// Load entity source
		/// </summary>
		object LoadSource(Entity entity);

		/// <summary>
		/// Save entity
		/// </summary>
		bool Save(Entity entity);

		/// <summary>
		/// Recycle entity
		/// </summary>
		bool Recycle(Entity entity);

		/// <summary>
		/// Reload entity
		/// </summary>
		bool Reload(Entity entity);
	}

	/// <summary>
	/// Entity List collection
	/// </summary>
	public interface IEntityList<TEntityType> : IList<TEntityType>, IEntityList
		where TEntityType : Entity
	{
		/// <summary>
		/// List metadata
		/// </summary>
		IListService<TEntityType> Service { get; }

		/// <summary>
		/// Create entity
		/// </summary>
		TEntityType Create(string entityName);

		/// <summary>
		/// Create entity
		/// </summary>
		TEntityType Create(Type entityType);

		/// <summary>
		/// Create entity
		/// </summary>
		TEntityType Create();

		/// <summary>
		/// Load entity
		/// </summary>
		bool Load(TEntityType entity);

		/// <summary>
		/// Load entity source
		/// </summary>
		object LoadSource(TEntityType entity);

		/// <summary>
		/// Save entity
		/// </summary>
		bool Save(TEntityType entity);

		/// <summary>
		/// Recycle entity
		/// </summary>
		bool Recycle(TEntityType entity);

		/// <summary>
		/// Reload entity
		/// </summary>
		bool Reload(TEntityType entity);

		/// <summary>
		/// Clone current list for cache
		/// </summary>
		IEntityList<TEntityType> CloneForCache();

		/// <summary>
		/// Clone cache list to current list
		/// </summary>
		/// <param name="cache"></param>
		void CloneFromCache(IEntityList<TEntityType> cache);

		/// <summary>
		/// Find entity in list by <paramref name="id"/>
		/// </summary>
		TEntityType FindById(Identifier id);
	}
}